#include <iostream>
#include "opencv2/opencv.hpp"
#include "sys/time.h"
using namespace std;
using namespace cv;

uint8_t resizedBuff[78 * 112 * 92];

int main() {
    timeval begin;
    timeval end;
    Mat img;
    img = imread("/home/yolaw/pic.jpg");

    float costTime = 0;

    for(int n = 0; n < 1000; n++){
        gettimeofday(&begin, nullptr);

        for(int i = 0; i < 78; i++){
            Mat um(92, 112, CV_8UC1, resizedBuff + i * 92 * 112);
            resize(img,um,Size(112,92), 0, 0, INTER_CUBIC);
        }
        gettimeofday(&end, nullptr);
        costTime += (end.tv_sec - begin.tv_sec) * 1000 + (end.tv_usec - begin.tv_usec) / 1000.0;
    }
    cout << "[NO OPENMP] avg cost time:" << costTime << "ms" << endl;

    costTime = 0;

    for(int n = 0; n < 1000; n++){
        gettimeofday(&begin, nullptr);

#pragma omp parallel for
        for(int i = 0; i < 78; i++){
            Mat um(92, 112, CV_8UC1, resizedBuff + i * 92 * 112);
            resize(img,um,Size(112,92), 0, 0, INTER_CUBIC);
        }
        gettimeofday(&end, nullptr);
        costTime += (end.tv_sec - begin.tv_sec) * 1000 + (end.tv_usec - begin.tv_usec) / 1000.0;
    }

    cout << "[OPENMP] avg cost time:" << costTime << "ms" << endl;

    return 0;
}